package com.aduerr.v1shouyin.mvp.activity;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.aduerr.v1shouyin.R;
import com.aduerr.v1shouyin.common.Constants;
import com.aduerr.v1shouyin.mvp.widget.CancelDialog;
import com.orhanobut.hawk.Hawk;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;


/**
 * @author HI
 * @email dev1024@foxmail.com
 * @time 2018/10/23 13:35
 * @change
 * @chang time
 * @class describe
 */

public class WriteOffActivity extends AppCompatActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;

    CancelDialog mCancelDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_writeoff);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(!Hawk.contains("hexiaopop")) {
            mCancelDialog.show(getSupportFragmentManager(), "");
        }
    }

    void initView() {
        tvTitle.setText("卡券核销");
        mCancelDialog = new CancelDialog();
    }

    @OnClick({R.id.ll_activity, R.id.btn_activity, R.id.ll_redpackage,
            R.id.btn_redpackage, R.id.img_back,})
    public void onViewClicked(View view) {
        switch(view.getId()) {
            case R.id.btn_activity:
            case R.id.ll_activity:
                Intent intent2 = new Intent(WriteOffActivity.this,
                        ScanningActivity.class);
                intent2.putExtra(Constants.QRCODE_CAPUTER,
                        Constants.CARD_COUPONS_VERIFY_QR);
                intent2.putExtra("tag", "xianxia");
                startActivity(intent2);
                break;
            //口碑券的核销
            case R.id.btn_redpackage:
            case R.id.ll_redpackage:
                Intent intent3 = new Intent(WriteOffActivity.this,
                        ScanningActivity.class);
                intent3.putExtra(Constants.QRCODE_CAPUTER,
                        Constants.PUBLIC_PRAISE_DETAILS);
                intent3.putExtra("tag", "koubei");
                startActivity(intent3);
                break;
            case R.id.img_back:
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void dismissDialog(String isDismiss) {
        if(isDismiss.equals("dismiss")) {
            mCancelDialog.getDialog().dismiss();
        }
    }
}
